package com.ali.juejin.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat.startActivity
import androidx.databinding.DataBindingUtil
import com.ali.juejin.BR
import com.ali.juejin.R
import com.ali.juejin.base.BaseModelListAdapter
import com.ali.juejin.bean.v1.Data
import com.ali.juejin.databinding.ItemRecommendArticleBinding
import com.ali.juejin.ui.activity.ArticleDetailActivity
import java.util.ArrayList

class HomeRecommendArticleAdapter(mContext:Context): BaseModelListAdapter<ItemRecommendArticleBinding, Data>(mContext,BR.recommendArticle) {

    override fun getLayout(): Int {
        return R.layout.item_recommend_article
    }

    override fun onBindViewHolder(holder: ListHolder<ItemRecommendArticleBinding>, position: Int) {
        super.onBindViewHolder(holder, position)
        holder.itemView.setOnClickListener {
            val data = list[position]
            startActivity(
                mContext,
                Intent(mContext, ArticleDetailActivity::class.java).putExtra(
                    "id",
                    data.item_info.article_id
                ).putStringArrayListExtra("tag_ids",
                    data.item_info.article_info.tag_ids as ArrayList<String>?
                )
                .putExtra("user_id",data.item_info.author_user_info.user_id)
                ,
                null
            )
        }
    }

}